package com.da.javatest.leetCode;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author chenlida
 * @date 2019/1/11 14:16
 * @description
 */
public class Code884 {
    public String[] uncommonFromSentences(String A, String B) {
        String[] s1 = A.split(" ");
        String[] s2 = B.split(" ");
        Map<String, Integer> map = new HashMap<>(s1.length + s2.length);
        for (String s : s1) {
            map.put(s, map.containsKey(s) ? map.get(s) + 1 : 1);
        }
        for (String s : s2) {
            map.put(s, map.containsKey(s) ? map.get(s) + 1 : 1);
        }
        List<String> c = map.entrySet().stream().filter(e -> e.getValue() == 1).map(e -> e.getKey()).collect(
            Collectors.toList());
        String[] result = new String[c.size()];
        c.toArray(result);
        return result;
    }
}
